package com.lhh.videoservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhh.springcommon.annotation.WebLog;
import com.lhh.springcommon.annotation.WithRequestId;
import com.lhh.springcommon.entity.Video;
import com.lhh.springcommon.entity.vo.CountVideoInfoVO;
import com.lhh.springcommon.entity.vo.VideoVO;
import com.lhh.springcommon.utils.PageQuery;
import com.lhh.springcommon.utils.Response;
import com.lhh.videoservice.service.VideoPlayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 视频播放
 * @author 李厚航
 */
@RestController
@RequestMapping("/videoPlay")
public class VideoPlayController {

    private final VideoPlayService videoPlayService;

    @Autowired
    public VideoPlayController(VideoPlayService videoPlayService) {
        this.videoPlayService = videoPlayService;
    }

    /**
     * 查询所有视频类别
     * @return 视频类别集合
     */
    @GetMapping("/queryClassification")
    @WithRequestId
    @WebLog
    public Response<List<String>> queryClassification(){
        return Response.success(videoPlayService.queryAllVideoClassification());
    }

    /**
     * 添加视频数据
     * @param video 视频数据
     * @return 视频数据
     */
    @PostMapping("/addVideo")
    @WithRequestId
    @WebLog
    public Response<Video> addVideo(@RequestBody Video video){
        return Response.success(videoPlayService.addVideo(video));
    }

    /**
     * 分页获取视频信息
     * @param page
     * @return
     */
    @PostMapping("/queryPageVideo")
    @WithRequestId
    @WebLog
    public Response<Page<VideoVO>> queryPageVideo(@RequestBody PageQuery<Video> page){
        return Response.success(videoPlayService.queryPageVideo(page));
    }

    /**
     * 删除视频
     * @param video
     * @return
     */
    @DeleteMapping("/deleteVideo")
    @WithRequestId
    @WebLog
    public Response<Boolean> deleteVideo(@RequestBody Video video){
        return Response.success(videoPlayService.deleteVideo(video));
    }

    /**
     * 获取上传文件的权限
     * @return
     */
    @GetMapping("/upload")
    @WithRequestId
    @WebLog
    public Response<Map<String,String>> upload(){
        return Response.success(videoPlayService.upload());
    }

    /**
     * 获取视频收藏数，点赞数
     * @param vid
     * @return
     */
    @GetMapping("/countByVid")
    @WithRequestId
    @WebLog
    public Response<CountVideoInfoVO> countByVid(@RequestParam("vid") Integer vid){
        return Response.success(videoPlayService.countVideoInfo(vid));
    }
}
